# http 处理器

from http.server import BaseHTTPRequestHandler

from dockerps_export.docker_ps_collector import DockerPsCollector


class MyHTTPRequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        try:
            metrics = DockerPsCollector.metrics()
            self.send_response(200)
        except BaseException:
            metrics = ""
            self.send_response(500)

        self.send_header("Content-type", "text/plain;  charset=utf-8")
        self.end_headers()
        self.wfile.write( bytes(metrics, 'utf-8') )
